//
//  UILable+Extension.swift
//  Sina
//
//  Created by maling  on 15/11/5.
//  Copyright © 2015年 maling . All rights reserved.
//

import UIKit

extension UILabel {


    //定义一个遍历构造方法 实现快速创建一个label
    // 参数后面的值 是默认值， 如果调用没有给有参数的值直接赋值 那么就会使用默认值
    convenience init(title: String,
        fontSize: CGFloat = 14,
        color: UIColor = UIColor.darkGrayColor(),
        screenInset: CGFloat = 0){  //默认跟屏幕边间距为0
    
//        let messageView = UILabel()
        self.init()
        text = title
        numberOfLines = 0
        font = UIFont.systemFontOfSize(fontSize)
       textColor = color        //换行
            if screenInset == 0 {
            textAlignment = NSTextAlignment.Center
            } else {
            
                //设置换行宽度，content内容左对齐
                preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 2 * screenInset
                textAlignment = NSTextAlignment.Left
            }
//        return messageView

       sizeToFit()
    
    }

    /*
    let messageView = UILabel()
    messageView.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
    messageView.textAlignment = NSTextAlignment.Center
    messageView.font = UIFont.systemFontOfSize(14)
    messageView.textColor = UIColor.darkGrayColor()
    //换行
    messageView.numberOfLines = 0
    
    
    return messageView
    */

}
